
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>[实现上下文环境保存与恢复] · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-katex/katex.min.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-emphasize/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism-tomorrow.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    


    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="part5.html" />
    
    
    <link rel="prev" href="part3.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../chapter0/introduction.html">
            
                <a href="../chapter0/introduction.html">
            
                    
                    第零章：实验环境说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../chapter1/introduction.html">
            
                <a href="../chapter1/introduction.html">
            
                    
                    第一章：独立式可执行程序
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../chapter1/part1.html">
            
                <a href="../chapter1/part1.html">
            
                    
                    [安装 nightly rust]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../chapter1/part2.html">
            
                <a href="../chapter1/part2.html">
            
                    
                    使用包管理器 cargo 创建 rust binary 项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../chapter1/part3.html">
            
                <a href="../chapter1/part3.html">
            
                    
                    移除标准库依赖
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../chapter1/part4.html">
            
                <a href="../chapter1/part4.html">
            
                    
                    [移除 runtime 依赖]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../chapter1/part5.html">
            
                <a href="../chapter1/part5.html">
            
                    
                    总结与展望
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../chapter2/introduction.html">
            
                <a href="../chapter2/introduction.html">
            
                    
                    第二章：最小化内核
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../chapter2/part1.html">
            
                <a href="../chapter2/part1.html">
            
                    
                    使用目标三元组描述目标平台
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../chapter2/part2.html">
            
                <a href="../chapter2/part2.html">
            
                    
                    编译、生成内核镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../chapter2/part3.html">
            
                <a href="../chapter2/part3.html">
            
                    
                    使用链接脚本指定内存布局
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../chapter2/part4.html">
            
                <a href="../chapter2/part4.html">
            
                    
                    [重写程序入口点 -start]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../chapter2/part5.html">
            
                <a href="../chapter2/part5.html">
            
                    
                    [使用 Qemu 运行内核]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../chapter2/part6.html">
            
                <a href="../chapter2/part6.html">
            
                    
                    封装 SBI 接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../chapter2/part7.html">
            
                <a href="../chapter2/part7.html">
            
                    
                    [实现格式化输出]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../chapter2/part8.html">
            
                <a href="../chapter2/part8.html">
            
                    
                    总结与展望
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="introduction.html">
            
                <a href="introduction.html">
            
                    
                    第三章：中断
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="part1.html">
            
                <a href="part1.html">
            
                    
                    rv64 中断介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="part2.html">
            
                <a href="part2.html">
            
                    
                    [手动触发断点中断]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="part3.html">
            
                <a href="part3.html">
            
                    
                    程序运行上下文环境
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.4" data-path="part4.html">
            
                <a href="part4.html">
            
                    
                    [实现上下文环境保存与恢复]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="part5.html">
            
                <a href="part5.html">
            
                    
                    [时钟中断]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="part6.html">
            
                <a href="part6.html">
            
                    
                    总结与展望
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../chapter4/introduction.html">
            
                <a href="../chapter4/introduction.html">
            
                    
                    第四章：内存管理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../chapter4/part1.html">
            
                <a href="../chapter4/part1.html">
            
                    
                    [物理内存探测与管理]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../chapter4/part2.html">
            
                <a href="../chapter4/part2.html">
            
                    
                    [动态内存分配]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../chapter4/part3.html">
            
                <a href="../chapter4/part3.html">
            
                    
                    总结与展望
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../chapter5/introduction.html">
            
                <a href="../chapter5/introduction.html">
            
                    
                    第五章：内存虚拟化
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../chapter5/part1.html">
            
                <a href="../chapter5/part1.html">
            
                    
                    页表：从虚拟内存到物理内存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../chapter5/part2.html">
            
                <a href="../chapter5/part2.html">
            
                    
                    [内核初始映射]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../chapter5/part3.html">
            
                <a href="../chapter5/part3.html">
            
                    
                    内核重映射
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../chapter5/part4.html">
            
                <a href="../chapter5/part4.html">
            
                    
                    内核重映射实现之一：页表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../chapter5/part5.html">
            
                <a href="../chapter5/part5.html">
            
                    
                    内核重映射实现之二：MemorySet
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../chapter5/part6.html">
            
                <a href="../chapter5/part6.html">
            
                    
                    [内核重映射实现之三：完结]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="../chapter5/part7.html">
            
                <a href="../chapter5/part7.html">
            
                    
                    总结与展望
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../chapter6/introduction.html">
            
                <a href="../chapter6/introduction.html">
            
                    
                    第六章：内核线程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../chapter6/part1.html">
            
                <a href="../chapter6/part1.html">
            
                    
                    线程状态与保存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../chapter6/part2.html">
            
                <a href="../chapter6/part2.html">
            
                    
                    线程切换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../chapter6/part3.html">
            
                <a href="../chapter6/part3.html">
            
                    
                    内核线程初始化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../chapter6/part4.html">
            
                <a href="../chapter6/part4.html">
            
                    
                    [内核线程创建与切换测试]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../chapter6/part5.html">
            
                <a href="../chapter6/part5.html">
            
                    
                    总结与展望
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../chapter7/introduction.html">
            
                <a href="../chapter7/introduction.html">
            
                    
                    第七章：线程调度
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../chapter7/part1.html">
            
                <a href="../chapter7/part1.html">
            
                    
                    线程池与线程管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../chapter7/part2.html">
            
                <a href="../chapter7/part2.html">
            
                    
                    内核调度线程 idle
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../chapter7/part3.html">
            
                <a href="../chapter7/part3.html">
            
                    
                    线程调度之 Round Robin 算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" data-path="../chapter7/part4.html">
            
                <a href="../chapter7/part4.html">
            
                    
                    [线程调度测试]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.5" data-path="../chapter7/part5.html">
            
                <a href="../chapter7/part5.html">
            
                    
                    总结与展望
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../chapter8/introduction.html">
            
                <a href="../chapter8/introduction.html">
            
                    
                    第八章：进程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../chapter8/part1.html">
            
                <a href="../chapter8/part1.html">
            
                    
                    [编写用户程序]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../chapter8/part1_1.html">
            
                <a href="../chapter8/part1_1.html">
            
                    
                    合并内核与应用程序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../chapter8/part2.html">
            
                <a href="../chapter8/part2.html">
            
                    
                    在内核中实现系统调用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../chapter8/part3.html">
            
                <a href="../chapter8/part3.html">
            
                    
                    创建虚拟内存空间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../chapter8/part4.html">
            
                <a href="../chapter8/part4.html">
            
                    
                    [创建进程]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="../chapter8/part5.html">
            
                <a href="../chapter8/part5.html">
            
                    
                    总结与展望
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../chapter9/introduction.html">
            
                <a href="../chapter9/introduction.html">
            
                    
                    第九章：文件系统
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../chapter9/part1.html">
            
                <a href="../chapter9/part1.html">
            
                    
                    [使用文件系统]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../chapter9/part2.html">
            
                <a href="../chapter9/part2.html">
            
                    
                    [实现记事本]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../chapter9/part3.html">
            
                <a href="../chapter9/part3.html">
            
                    
                    [实现终端]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../chapter9/part4.html">
            
                <a href="../chapter9/part4.html">
            
                    
                    [文件读写]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../chapter9/part5.html">
            
                <a href="../chapter9/part5.html">
            
                    
                    总结与展望
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../chapter10/introduction.html">
            
                <a href="../chapter10/introduction.html">
            
                    
                    第十章：同步互斥
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../exercise/introduction.html">
            
                <a href="../exercise/introduction.html">
            
                    
                    练习题
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../exercise/part1.html">
            
                <a href="../exercise/part1.html">
            
                    
                    1. 中断异常
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../exercise/part2.html">
            
                <a href="../exercise/part2.html">
            
                    
                    2. 物理内存管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="../exercise/part3.html">
            
                <a href="../exercise/part3.html">
            
                    
                    3. 虚拟内存管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.4" data-path="../exercise/part4.html">
            
                <a href="../exercise/part4.html">
            
                    
                    4. 线程管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.5" data-path="../exercise/part5.html">
            
                <a href="../exercise/part5.html">
            
                    
                    5. 用户进程（+ 虚拟内存管理 + 线程管理）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.6" data-path="../exercise/part6.html">
            
                <a href="../exercise/part6.html">
            
                    
                    6. CPU 调度
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.7" data-path="../exercise/part7.html">
            
                <a href="../exercise/part7.html">
            
                    
                    7. 同步互斥
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.8" data-path="../exercise/part8.html">
            
                <a href="../exercise/part8.html">
            
                    
                    8. 文件系统
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../appendix/introduction.html">
            
                <a href="../appendix/introduction.html">
            
                    
                    附录
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1" data-path="../appendix/inline_asm.html">
            
                <a href="../appendix/inline_asm.html">
            
                    
                    内联汇编
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2" data-path="../appendix/install_rust.html">
            
                <a href="../appendix/install_rust.html">
            
                    
                    安装 rust
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >[实现上下文环境保存与恢复]</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x5B9E;&#x73B0;&#x4E0A;&#x4E0B;&#x6587;&#x73AF;&#x5883;&#x4FDD;&#x5B58;&#x4E0E;&#x6062;&#x590D;">&#x5B9E;&#x73B0;&#x4E0A;&#x4E0B;&#x6587;&#x73AF;&#x5883;&#x4FDD;&#x5B58;&#x4E0E;&#x6062;&#x590D;</h2>
<ul>
<li><a href="https://github.com/rcore-os/rCore_tutorial/tree/ch3-pa4" target="_blank">&#x4EE3;&#x7801;</a></li>
</ul>
<p>OS &#x5728;&#x6B63;&#x786E;&#x5B8C;&#x6210;&#x4E2D;&#x65AD;&#x521D;&#x59CB;&#x5316;&#xFF08;&#x8BBE;&#x7F6E;&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x7684;&#x8D77;&#x59CB;&#x5730;&#x5740;&#xFF0C;&#x5E76;&#x4F7F;&#x80FD;&#x4E2D;&#x65AD;&#xFF09;&#x540E;&#xFF0C;&#x8FD8;&#x9700;&#x4E3A;&#x88AB;&#x4E2D;&#x65AD;&#x7684;&#x7A0B;&#x5E8F;&#x4FDD;&#x5B58;&#x548C;&#x6062;&#x590D;&#x5F53;&#x65F6;&#x7A0B;&#x5E8F;&#x8FD0;&#x884C;&#x65F6;&#x7684;&#x4E0A;&#x4E0B;&#x6587;&#xFF08;&#x5B9E;&#x9645;&#x4E0A;&#x5C31;&#x662F;&#x4E00;&#x5806;&#x5BC4;&#x5B58;&#x5668;&#x7684;&#x503C;&#xFF0C;&#x5177;&#x4F53;&#x5185;&#x5BB9;&#x5728;<a href="part3.html">part3 &#x4E2D;&#x63CF;&#x8FF0;&#x7684;<strong>&#x4E2D;&#x65AD;&#x5E27;(TrapFrame)</strong>&#x7ED3;&#x6784;&#x4F53;</a>&#x4E2D;&#x6709;&#x8BE6;&#x7EC6;&#x5B9A;&#x4E49;&#xFF09;</p>
<pre class="language-"><code class="lang-riscv"><span class="token comment"># src/trap/trap.asm
</span>
    <span class="token section-directives tag">.section</span> <span class="token section-directives tag">.text</span>
    <span class="token symbol-directives tag">.globl</span> <span class="token last-literals operator">__alltraps</span>
    <span class="token alignment-directives tag">.align</span> <span class="token number">4</span>
<span class="token labels operator">__alltraps:</span>
    <span class="token last-literals operator">SAVE_ALL</span>
    <span class="token pseudo-instructions important">mv</span> <span class="token general-registers class-name">a0</span>, <span class="token general-registers class-name">sp</span>
    <span class="token rv32/64i-instructions keyword">jal</span> <span class="token last-literals operator">rust_trap</span>

    <span class="token symbol-directives tag">.globl</span> <span class="token last-literals operator">__trapret</span>
<span class="token labels operator">__trapret:</span>
    <span class="token last-literals operator">RESTORE_ALL</span>
    <span class="token privilege-instructions keyword">sret</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x9996;&#x5148;&#x5B9A;&#x4E49; <code>__alltraps</code> &#x51FD;&#x6570;&#x4F5C;&#x4E3A;&#x6240;&#x6709;&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x7684;&#x5165;&#x53E3;&#xFF0C;&#x8FD9;&#x91CC;&#x6211;&#x4EEC;&#x9996;&#x5148;&#x901A;&#x8FC7; <code>SAVE_ALL</code> &#xFF08;&#x6C47;&#x7F16;&#x5B8F;&#xFF09;&#x6765;&#x4FDD;&#x5B58;&#x4E0A;&#x4E0B;&#x6587;&#x73AF;&#x5883;&#xFF0C;&#x968F;&#x540E;&#x5C06;&#x5F53;&#x524D;&#x6808;&#x9876;&#x5730;&#x5740; <code>sp</code> &#x7684;&#x503C;&#x7ED9;&#x5230;&#x5BC4;&#x5B58;&#x5668; <code>a0</code> &#xFF0C;&#x8FD9;&#x662F;&#x56E0;&#x4E3A;&#x5728; risc-v calling convention &#x4E2D;&#xFF0C;&#x89C4;&#x5B9A; <code>a0</code> &#x4FDD;&#x5B58;&#x51FD;&#x6570;&#x8F93;&#x5165;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x4E8E;&#x662F;&#x5C31;&#x76F8;&#x5F53;&#x4E8E;&#x5C06;&#x6808;&#x9876;&#x5730;&#x5740;&#x4F20;&#x7ED9;&#x51FD;&#x6570; <code>rust_trap</code> &#x4F5C;&#x4E3A;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x3002;&#x6B63;&#x5982;&#x6211;&#x4EEC;&#x4E4B;&#x524D;&#x63D0;&#x53CA;&#x7684;&#xFF0C;__alltraps &#x9700;&#x8981;&#x4EE5;&#x56DB;&#x5B57;&#x8282;&#x5BF9;&#x9F50;&#x3002;</p>
<p>&#x968F;&#x540E;&#xFF0C;&#x6211;&#x4EEC;&#x901A;&#x8FC7; <code>jal</code> &#x8C03;&#x7528; <code>rust_trap</code> &#x51FD;&#x6570;&#x5E76;&#x5728;&#x8FD4;&#x56DE;&#x4E4B;&#x540E;&#x8DF3;&#x8F6C;&#x5230;&#x8C03;&#x7528;&#x8BED;&#x53E5;&#x7684;&#x4E0B;&#x4E00;&#x6761;&#x6307;&#x4EE4;&#x3002;&#x5B9E;&#x9645;&#x4E0A;&#x8C03;&#x7528;&#x8FD4;&#x56DE;&#x4E4B;&#x540E;&#x8FDB;&#x5165; <code>__trapret</code> &#x51FD;&#x6570;&#xFF0C;&#x8FD9;&#x91CC;&#x6211;&#x4EEC;&#x901A;&#x8FC7; <code>RESTORE_ALL</code> &#xFF08;&#x6C47;&#x7F16;&#x5B8F;&#xFF09;&#x6062;&#x590D;&#x4E2D;&#x65AD;&#x4E4B;&#x524D;&#x7684;&#x4E0A;&#x4E0B;&#x6587;&#x73AF;&#x5883;&#xFF0C;&#x5E76;&#x6700;&#x7EC8;&#x901A;&#x8FC7;&#x4E00;&#x6761; <code>sret</code> &#x6307;&#x4EE4;&#x8DF3;&#x8F6C;&#x5230; <code>sepc</code>&#x6307;&#x5411;&#x7684;&#x5730;&#x5740;&#xFF0C;&#x5373;&#x56DE;&#x5230;&#x89E6;&#x53D1;&#x4E2D;&#x65AD;&#x7684;&#x90A3;&#x6761;&#x6307;&#x4EE4;&#x6240;&#x5728;&#x5730;&#x5740;&#x3002;&#x8FD9;&#x4F1A;&#x5BFC;&#x81F4;&#x89E6;&#x53D1;&#x4E2D;&#x65AD;&#x7684;&#x90A3;&#x6761;&#x6307;&#x4EE4;&#x53C8;&#x88AB;&#x6267;&#x884C;&#x4E00;&#x6B21;&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x7531;&#x4E8E;&#x8FD9;&#x90E8;&#x5206;&#x7528;&#x5230;&#x4E86; <code>SAVE_ALL</code> &#x548C; <code>RESTORE_ALL</code> &#x4E24;&#x4E2A;&#x6C47;&#x7F16;&#x5B8F;&#xFF0C;&#x6240;&#x4EE5;&#x8FD9;&#x90E8;&#x5206;&#x5FC5;&#x987B;&#x5199;&#x5728;&#x6700;&#x4E0B;&#x9762;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x5B9A;&#x4E49;&#x51E0;&#x4E2A;&#x5E38;&#x91CF;&#x548C;&#x5B8F;&#xFF1A;</p>
<pre class="language-"><code class="lang-riscv"><span class="token comment"># src/trap/trap.asm
</span>
<span class="token comment"># &#x5E38;&#x91CF;&#xFF1A;&#x8868;&#x793A;&#x6BCF;&#x4E2A;&#x5BC4;&#x5B58;&#x5668;&#x5360;&#x7684;&#x5B57;&#x8282;&#x6570;&#xFF0C;&#x7531;&#x4E8E;&#x662F;64&#x4F4D;&#xFF0C;&#x90FD;&#x662F;8&#x5B57;&#x8282;
</span><span class="token symbol-directives tag">.equ</span> <span class="token last-literals operator">XLENB</span>, <span class="token number">8</span>

<span class="token comment"># &#x5C06;&#x5730;&#x5740; sp+8*a2 &#x5904;&#x7684;&#x503C; load &#x5230;&#x5BC4;&#x5B58;&#x5668; a1 &#x5185;
</span><span class="token miscellaneous-directives tag">.macro</span> <span class="token last-literals operator">LOAD</span> <span class="token general-registers class-name">a1</span>, <span class="token general-registers class-name">a2</span>
    <span class="token rv32/64i-instructions keyword">ld</span> \<span class="token general-registers class-name">a1</span>, \<span class="token general-registers class-name">a2</span>*<span class="token last-literals operator">XLENB</span>(<span class="token general-registers class-name">sp</span>)
<span class="token miscellaneous-directives tag">.endm</span>

<span class="token comment"># &#x5C06;&#x5BC4;&#x5B58;&#x5668; a1 &#x5185;&#x7684;&#x503C; store &#x5230;&#x5730;&#x5740; sp+8*a2 &#x5185;
</span><span class="token miscellaneous-directives tag">.macro</span> <span class="token last-literals operator">STORE</span> <span class="token general-registers class-name">a1</span>, <span class="token general-registers class-name">a2</span>
    <span class="token rv32/64i-instructions keyword">sd</span> \<span class="token general-registers class-name">a1</span>, \<span class="token general-registers class-name">a2</span>*<span class="token last-literals operator">XLENB</span>(<span class="token general-registers class-name">sp</span>)
<span class="token miscellaneous-directives tag">.endm</span>
</code></pre>
<h3 id="&#x4FDD;&#x5B58;&#x4E0A;&#x4E0B;&#x6587;&#x73AF;&#x5883;">&#x4FDD;&#x5B58;&#x4E0A;&#x4E0B;&#x6587;&#x73AF;&#x5883;</h3>
<p><code>SAVE_ALL</code> &#x7684;&#x539F;&#x7406;&#x662F;&#xFF1A;&#x5C06;&#x4E00;&#x6574;&#x4E2A; <code>TrapFrame</code> &#x4FDD;&#x5B58;&#x5728;<strong>&#x5185;&#x6838;&#x6808;</strong>&#x4E0A;&#x3002;&#x6211;&#x4EEC;&#x73B0;&#x5728;&#x5C31;&#x5904;&#x5728;&#x5185;&#x6838;&#x6001;(S &#x6001;)&#xFF0C;&#x56E0;&#x6B64;&#x73B0;&#x5728;&#x7684;&#x6808;&#x9876;&#x5730;&#x5740; <code>sp</code> &#x5C31;&#x6307;&#x5411;&#x5185;&#x6838;&#x6808;&#x5730;&#x5740;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x4E4B;&#x540E;&#x6211;&#x4EEC;&#x8FD8;&#x8981;&#x652F;&#x6301;&#x8FD0;&#x884C;<strong>&#x7528;&#x6237;&#x6001;&#x7A0B;&#x5E8F;</strong>&#xFF0C;&#x987E;&#x540D;&#x601D;&#x4E49;&#xFF0C;&#x8981;&#x5728;&#x7528;&#x6237;&#x6001;(U &#x6001;)&#x4E0A;&#x8FD0;&#x884C;&#xFF0C;&#x5728;&#x4E2D;&#x65AD;&#x65F6;&#x6808;&#x9876;&#x5730;&#x5740; <code>sp</code> &#x5C06;&#x6307;&#x5411;&#x7528;&#x6237;&#x6808;&#x9876;&#x5730;&#x5740;&#xFF0C;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0B;&#x6211;&#x4EEC;&#x8981;&#x4ECE;&#x7528;&#x6237;&#x6808;&#x5207;&#x6362;&#x5230;&#x5185;&#x6838;&#x6808;&#x3002;</p>
<pre class="language-"><code class="lang-riscv"><span class="token comment"># src/trap/trap.asm
</span>
<span class="token comment"># &#x89C4;&#x5B9A;&#x82E5;&#x5728;&#x4E2D;&#x65AD;&#x4E4B;&#x524D;&#x5904;&#x4E8E; U &#x6001;(&#x7528;&#x6237;&#x6001;)
</span><span class="token comment"># &#x5219; sscratch &#x4FDD;&#x5B58;&#x7684;&#x662F;&#x5185;&#x6838;&#x6808;&#x5730;&#x5740;
</span><span class="token comment"># &#x5426;&#x5219;&#x4E2D;&#x65AD;&#x4E4B;&#x524D;&#x5904;&#x4E8E; S &#x6001;(&#x5185;&#x6838;&#x6001;)&#xFF0C;sscratch &#x4FDD;&#x5B58;&#x7684;&#x662F; 0
</span><span class="token miscellaneous-directives tag">.macro</span> <span class="token last-literals operator">SAVE_ALL</span>
    <span class="token comment"># &#x901A;&#x8FC7;&#x539F;&#x5B50;&#x64CD;&#x4F5C;&#x4EA4;&#x6362; sp, sscratch
</span>    <span class="token comment"># &#x5B9E;&#x9645;&#x4E0A;&#x662F;&#x5C06;&#x53F3;&#x4FA7;&#x5BC4;&#x5B58;&#x5668;&#x7684;&#x503C;&#x5199;&#x5165;&#x4E2D;&#x95F4; csr
</span>    <span class="token comment"># &#x5E76;&#x5C06;&#x4E2D;&#x95F4; csr &#x7684;&#x503C;&#x5199;&#x5165;&#x5DE6;&#x4FA7;&#x5BC4;&#x5B58;&#x5668;
</span>    <span class="token csr-instructions keyword">csrrw</span> <span class="token general-registers class-name">sp</span>, <span class="token s-mode-csrs class-name">sscratch</span>, <span class="token general-registers class-name">sp</span>

    <span class="token comment"># &#x5982;&#x679C; sp=0 &#xFF0C;&#x8BF4;&#x660E;&#x4EA4;&#x6362;&#x524D; sscratch=0
</span>    <span class="token comment">#   &#x5219;&#x8BF4;&#x660E;&#x4ECE;&#x5185;&#x6838;&#x6001;&#x8FDB;&#x5165;&#x4E2D;&#x65AD;&#xFF0C;&#x4E0D;&#x7528;&#x5207;&#x6362;&#x6808;
</span>    <span class="token comment">#   &#x56E0;&#x6B64;&#x4E0D;&#x8DF3;&#x8F6C;&#xFF0C;&#x7EE7;&#x7EED;&#x6267;&#x884C; csrr &#x518D;&#x5C06; sscratch &#x7684;&#x503C;&#x8BFB;&#x56DE; sp
</span>    <span class="token comment">#   &#x6B64;&#x65F6; sp,sscratch &#x5747;&#x4FDD;&#x5B58;&#x5185;&#x6838;&#x6808;
</span>
    <span class="token comment">#   &#x5426;&#x5219; &#x8BF4;&#x660E;sp!=0&#xFF0C;&#x8BF4;&#x660E;&#x4ECE;&#x7528;&#x6237;&#x6001;&#x8FDB;&#x5165;&#x4E2D;&#x65AD;&#xFF0C;&#x8981;&#x5207;&#x6362;&#x6808;
</span>    <span class="token comment">#   &#x7531;&#x4E8E; sscratch &#x89C4;&#x5B9A;&#xFF0C;&#x4E8C;&#x8005;&#x4EA4;&#x6362;&#x540E;
</span>    <span class="token comment">#   &#x6B64;&#x65F6; sp &#x4E3A;&#x5185;&#x6838;&#x6808;&#xFF0C; sscratch &#x4E3A;&#x7528;&#x6237;&#x6808;
</span>    <span class="token comment">#   &#x7565;&#x8FC7; csrr &#x6307;&#x4EE4;
</span>
    <span class="token comment"># &#x4E24;&#x79CD;&#x60C5;&#x51B5;&#x63A5;&#x4E0B;&#x6765;&#x90FD;&#x662F;&#x5728;&#x5185;&#x6838;&#x6808;&#x4E0A;&#x4FDD;&#x5B58;&#x4E0A;&#x4E0B;&#x6587;&#x73AF;&#x5883;
</span>    <span class="token pseudo-instructions important">bnez</span> <span class="token general-registers class-name">sp</span>, <span class="token last-literals operator">trap_from_user</span>
<span class="token labels operator">trap_from_kernel:</span>
    <span class="token csr-instructions keyword">csrr</span> <span class="token general-registers class-name">sp</span>, <span class="token s-mode-csrs class-name">sscratch</span>
<span class="token labels operator">trap_from_user:</span>
    <span class="token comment"># &#x63D0;&#x524D;&#x5206;&#x914D;&#x6808;&#x5E27;
</span>    <span class="token rv32/64i-instructions keyword">addi</span> <span class="token general-registers class-name">sp</span>, <span class="token general-registers class-name">sp</span>, -<span class="token number">36</span>*<span class="token last-literals operator">XLENB</span>
    <span class="token comment"># &#x6309;&#x7167;&#x5730;&#x5740;&#x9012;&#x589E;&#x7684;&#x987A;&#x5E8F;&#xFF0C;&#x4FDD;&#x5B58;&#x9664;x0, x2&#x4E4B;&#x5916;&#x7684;&#x901A;&#x7528;&#x5BC4;&#x5B58;&#x5668;
</span>    <span class="token comment"># x0 &#x6052;&#x4E3A; 0 &#x4E0D;&#x5FC5;&#x4FDD;&#x5B58;
</span>    <span class="token comment"># x2 &#x4E3A; sp &#x5BC4;&#x5B58;&#x5668;&#xFF0C;&#x9700;&#x7279;&#x6B8A;&#x5904;&#x7406;
</span>    <span class="token last-literals operator">STORE</span> <span class="token general-registers class-name">x1</span>, <span class="token number">1</span>
    <span class="token last-literals operator">STORE</span> <span class="token general-registers class-name">x3</span>, <span class="token number">3</span>
    <span class="token last-literals operator">STORE</span> <span class="token general-registers class-name">x4</span>, <span class="token number">4</span>
    ...
    <span class="token last-literals operator">STORE</span> <span class="token general-registers class-name">x30</span>, <span class="token number">30</span>
    <span class="token last-literals operator">STORE</span> <span class="token general-registers class-name">x31</span>, <span class="token number">31</span>

    <span class="token comment"># &#x82E5;&#x4ECE;&#x5185;&#x6838;&#x6001;&#x8FDB;&#x5165;&#x4E2D;&#x65AD;&#xFF0C;&#x6B64;&#x65F6; sscratch &#x4E3A;&#x5185;&#x6838;&#x6808;&#x5730;&#x5740;
</span>    <span class="token comment"># &#x82E5;&#x4ECE;&#x7528;&#x6237;&#x6001;&#x8FDB;&#x5165;&#x4E2D;&#x65AD;&#xFF0C;&#x6B64;&#x65F6; sscratch &#x4E3A;&#x7528;&#x6237;&#x6808;&#x5730;&#x5740;
</span>    <span class="token comment"># &#x5C06; sscratch &#x7684;&#x503C;&#x4FDD;&#x5B58;&#x5728; s0 &#x4E2D;&#xFF0C;&#x5E76;&#x5C06; sscratch &#x6E05;&#x96F6;
</span>    <span class="token csr-instructions keyword">csrrw</span> <span class="token general-registers class-name">s0</span>, <span class="token s-mode-csrs class-name">sscratch</span>, <span class="token general-registers class-name">x0</span>
    <span class="token comment"># &#x5206;&#x522B;&#x5C06;&#x56DB;&#x4E2A;&#x5BC4;&#x5B58;&#x5668;&#x7684;&#x503C;&#x4FDD;&#x5B58;&#x5728; s1,s2,s3,s4 &#x4E2D;
</span>    <span class="token csr-instructions keyword">csrr</span> <span class="token general-registers class-name">s1</span>, <span class="token s-mode-csrs class-name">sstatus</span>
    <span class="token csr-instructions keyword">csrr</span> <span class="token general-registers class-name">s2</span>, <span class="token s-mode-csrs class-name">sepc</span>
    <span class="token csr-instructions keyword">csrr</span> <span class="token general-registers class-name">s3</span>, <span class="token s-mode-csrs class-name">stval</span>
    <span class="token csr-instructions keyword">csrr</span> <span class="token general-registers class-name">s4</span>, <span class="token s-mode-csrs class-name">scause</span>

    <span class="token comment"># &#x5C06; s0 &#x4FDD;&#x5B58;&#x5728;&#x6808;&#x4E0A;
</span>    <span class="token last-literals operator">STORE</span> <span class="token general-registers class-name">s0</span>, <span class="token number">2</span>
    <span class="token comment"># &#x5C06; s1,s2,s3,s4 &#x4FDD;&#x5B58;&#x5728;&#x6808;&#x4E0A;
</span>    <span class="token last-literals operator">STORE</span> <span class="token general-registers class-name">s1</span>, <span class="token number">32</span>
    <span class="token last-literals operator">STORE</span> <span class="token general-registers class-name">s2</span>, <span class="token number">33</span>
    <span class="token last-literals operator">STORE</span> <span class="token general-registers class-name">s3</span>, <span class="token number">34</span>
    <span class="token last-literals operator">STORE</span> <span class="token general-registers class-name">s4</span>, <span class="token number">35</span>
<span class="token miscellaneous-directives tag">.endm</span>
</code></pre>
<p>&#x5728; <code>SAVE_ALL</code> &#x4E4B;&#x540E;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x4E00;&#x6574;&#x4E2A; <code>TrapFrame</code> &#x5B58;&#x5728;&#x4E86;&#x5185;&#x6838;&#x6808;&#x4E0A;&#xFF0C;&#x4E14;&#x5728;&#x5730;&#x5740;&#x533A;&#x95F4;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mo>[</mo><mtext><mi mathvariant="normal">s</mi><mi mathvariant="normal">p</mi></mtext><mo separator="true">,</mo><mtext><mi mathvariant="normal">s</mi><mi mathvariant="normal">p</mi></mtext><mo>+</mo><mn>3</mn><mn>6</mn><mo>&#xD7;</mo><mn>8</mn><mo>)</mo></mrow><annotation encoding="application/x-tex">[\text{sp},\text{sp}+36\times8)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mopen">[</span><span class="mord text textstyle uncramped"><span class="mord mathrm">sp</span></span><span class="mpunct">,</span><span class="mord text textstyle uncramped"><span class="mord mathrm">sp</span></span><span class="mbin">+</span><span class="mord mathrm">3</span><span class="mord mathrm">6</span><span class="mbin">&#xD7;</span><span class="mord mathrm">8</span><span class="mclose">)</span></span></span></span>&#x4E0A;&#x6309;&#x7167;&#x987A;&#x5E8F;&#x5B58;&#x653E;&#x4E86; <code>TrapFrame</code> &#x7684;&#x5404;&#x4E2A;&#x5B57;&#x6BB5;&#x3002;&#x8FD9;&#x6837;&#xFF0C;<code>rust_trap</code> &#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x6808;&#x9876;&#x5730;&#x5740;&#x6B63;&#x786E;&#x8BBF;&#x95EE; <code>TrapFrame</code> &#x4E86;&#x3002;</p>
<h3 id="&#x6062;&#x590D;&#x4E0A;&#x4E0B;&#x6587;&#x73AF;&#x5883;">&#x6062;&#x590D;&#x4E0A;&#x4E0B;&#x6587;&#x73AF;&#x5883;</h3>
<p>&#x800C; <code>RESTORE_ALL</code> &#x6B63;&#x597D;&#x662F;&#x4E00;&#x4E2A;&#x53CD;&#x8FC7;&#x6765;&#x7684;&#x8FC7;&#x7A0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-riscv"><span class="token comment"># src/trap/trap.asm
</span>
<span class="token miscellaneous-directives tag">.macro</span> <span class="token last-literals operator">RESTORE_ALL</span>
    <span class="token comment"># s1 = sstatus
</span>    <span class="token last-literals operator">LOAD</span> <span class="token general-registers class-name">s1</span>, <span class="token number">32</span>
    <span class="token comment"># s2 = sepc
</span>    <span class="token last-literals operator">LOAD</span> <span class="token general-registers class-name">s2</span>, <span class="token number">33</span>
    <span class="token comment"># &#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x53E6;&#x4E00;&#x79CD;&#x65B9;&#x5F0F;&#x5224;&#x65AD;&#x662F;&#x4ECE;&#x5185;&#x6838;&#x6001;&#x8FD8;&#x662F;&#x7528;&#x6237;&#x6001;&#x8FDB;&#x5165;&#x4E2D;&#x65AD;
</span>    <span class="token comment"># &#x5982;&#x679C;&#x4ECE;&#x5185;&#x6838;&#x6001;&#x8FDB;&#x5165;&#x4E2D;&#x65AD;&#xFF0C; sstatus &#x7684; SPP &#x4F4D;&#x88AB;&#x786C;&#x4EF6;&#x8BBE;&#x4E3A; 1
</span>    <span class="token comment"># &#x5982;&#x679C;&#x4ECE;&#x7528;&#x6237;&#x6001;&#x8FDB;&#x5165;&#x4E2D;&#x65AD;&#xFF0C; sstatus &#x7684; SPP &#x4F4D;&#x88AB;&#x786C;&#x4EF6;&#x8BBE;&#x4E3A; 0
</span>    <span class="token comment"># &#x53D6;&#x51FA; sstatus &#x7684; SPP
</span>    <span class="token rv32/64i-instructions keyword">andi</span> <span class="token general-registers class-name">s0</span>, <span class="token general-registers class-name">s1</span>, <span class="token number">1</span> &lt;&lt; <span class="token number">8</span>
    <span class="token comment"># &#x82E5; SPP=0 &#xFF0C; &#x4ECE;&#x7528;&#x6237;&#x6001;&#x8FDB;&#x5165;&#x4E2D;&#x65AD;&#xFF0C;&#x8FDB;&#x884C; _to_user &#x989D;&#x5916;&#x5904;&#x7406;
</span>    <span class="token pseudo-instructions important">bnez</span> <span class="token general-registers class-name">s0</span>, <span class="token last-literals operator">_to_kernel</span>
<span class="token labels operator">_to_user:</span>
    <span class="token comment"># &#x91CA;&#x653E;&#x5728;&#x5185;&#x6838;&#x6808;&#x4E0A;&#x5206;&#x914D;&#x7684;&#x5185;&#x5B58;
</span>    <span class="token rv32/64i-instructions keyword">addi</span> <span class="token general-registers class-name">s0</span>, <span class="token general-registers class-name">sp</span>, <span class="token number">36</span> * <span class="token last-literals operator">XLENB</span>
    <span class="token comment"># RESTORE_ALL &#x4E4B;&#x540E;&#xFF0C;&#x5982;&#x679C;&#x4ECE;&#x7528;&#x6237;&#x6001;&#x8FDB;&#x5165;&#x4E2D;&#x65AD;
</span>    <span class="token comment"># sscratch &#x6307;&#x5411;&#x7528;&#x6237;&#x6808;&#x5730;&#x5740;&#xFF01;
</span>    <span class="token comment"># &#x73B0;&#x5728;&#x4EE4; sscratch &#x6307;&#x5411;&#x5185;&#x6838;&#x6808;&#x9876;&#x5730;&#x5740;
</span>    <span class="token comment"># &#x5982;&#x679C;&#x662F;&#x4ECE;&#x5185;&#x6838;&#x6001;&#x8FDB;&#x5165;&#x4E2D;&#x65AD;&#xFF0C;&#x5728; SAVE_ALL &#x91CC;&#x9762;
</span>    <span class="token comment"># &#x5C31;&#x628A; sscratch &#x6E05;&#x96F6;&#x4E86;&#xFF0C;&#x56E0;&#x6B64;&#x4FDD;&#x8BC1;&#x4E86;&#x6211;&#x4EEC;&#x7684;&#x89C4;&#x5B9A;
</span>    <span class="token csr-instructions keyword">csrw</span> <span class="token s-mode-csrs class-name">sscratch</span>, <span class="token general-registers class-name">s0</span>
<span class="token labels operator">_to_kernel:</span>
    <span class="token comment"># &#x6062;&#x590D; sstatus, sepc &#x5BC4;&#x5B58;&#x5668;
</span>    <span class="token csr-instructions keyword">csrw</span> <span class="token s-mode-csrs class-name">sstatus</span>, <span class="token general-registers class-name">s1</span>
    <span class="token csr-instructions keyword">csrw</span> <span class="token s-mode-csrs class-name">sepc</span>, <span class="token general-registers class-name">s2</span>

    <span class="token comment"># &#x6062;&#x590D;&#x9664; x0, x2(sp) &#x4E4B;&#x5916;&#x7684;&#x901A;&#x7528;&#x5BC4;&#x5B58;&#x5668;
</span>    <span class="token last-literals operator">LOAD</span> <span class="token general-registers class-name">x1</span>, <span class="token number">1</span>
    <span class="token last-literals operator">LOAD</span> <span class="token general-registers class-name">x3</span>, <span class="token number">3</span>
    <span class="token last-literals operator">LOAD</span> <span class="token general-registers class-name">x4</span>, <span class="token number">4</span>
    ...
    <span class="token last-literals operator">LOAD</span> <span class="token general-registers class-name">x31</span>, <span class="token number">31</span>

    <span class="token comment"># &#x5982;&#x679C;&#x4ECE;&#x7528;&#x6237;&#x6001;&#x8FDB;&#x5165;&#x4E2D;&#x65AD;&#xFF0C; sp+2*8 &#x5730;&#x5740;&#x5904;&#x4FDD;&#x5B58;&#x7528;&#x6237;&#x6808;&#x9876;&#x5730;&#x5740;
</span>    <span class="token comment"># &#x5207;&#x6362;&#x56DE;&#x7528;&#x6237;&#x6808;
</span>    <span class="token comment"># &#x5982;&#x679C;&#x4ECE;&#x5185;&#x6838;&#x6001;&#x8FDB;&#x5165;&#x4E2D;&#x65AD;&#xFF0C; sp+2*8 &#x5730;&#x5740;&#x5904;&#x4FDD;&#x5B58;&#x5185;&#x6838;&#x6808;&#x9876;&#x5730;&#x5740;
</span>    <span class="token comment"># &#x5207;&#x6362;&#x56DE;&#x5185;&#x6838;&#x6808;
</span>    <span class="token last-literals operator">LOAD</span> <span class="token general-registers class-name">x2</span>, <span class="token number">2</span>
<span class="token miscellaneous-directives tag">.endm</span>
</code></pre>
<p>&#x73B0;&#x5728;&#x662F;&#x65F6;&#x5019;&#x5B9E;&#x73B0;&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x51FD;&#x6570; <code>rust_trap</code>&#x4E86;&#xFF01;</p>
<pre class="language-"><code class="lang-rust"><span class="token comment">// src/interrupt.rs</span>

<span class="token comment">// &#x5F15;&#x5165; TrapFrame &#x7ED3;&#x6784;&#x4F53;</span>
<span class="token keyword">use</span> <span class="token keyword">crate</span><span class="token module-declaration namespace"><span class="token punctuation">::</span>context<span class="token punctuation">::</span></span><span class="token class-name">TrapFrame</span><span class="token punctuation">;</span>

<span class="token comment">// &#x8F7D;&#x5165; trap.asm</span>
<span class="token macro property">global_asm!</span><span class="token punctuation">(</span><span class="token macro property">include_str!</span><span class="token punctuation">(</span><span class="token string">&quot;trap/trap.asm&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">pub</span> <span class="token keyword">fn</span> <span class="token function-definition function">init</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">unsafe</span> <span class="token punctuation">{</span>
        <span class="token keyword">extern</span> <span class="token string">&quot;C&quot;</span> <span class="token punctuation">{</span>
            <span class="token comment">// &#x4E2D;&#x65AD;&#x5904;&#x7406;&#x603B;&#x5165;&#x53E3;</span>
            <span class="token keyword">fn</span> <span class="token function-definition function">__alltraps</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token comment">// &#x7ECF;&#x8FC7;&#x4E0A;&#x9762;&#x7684;&#x5206;&#x6790;&#xFF0C;&#x7531;&#x4E8E;&#x73B0;&#x5728;&#x662F;&#x5728;&#x5185;&#x6838;&#x6001;</span>
        <span class="token comment">// &#x6211;&#x4EEC;&#x8981;&#x628A; sscratch &#x521D;&#x59CB;&#x5316;&#x4E3A; 0</span>
        <span class="token namespace">sscratch<span class="token punctuation">::</span></span><span class="token function">write</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// &#x4ECD;&#x4F7F;&#x7528; Direct &#x6A21;&#x5F0F;</span>
        <span class="token comment">// &#x5C06;&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x603B;&#x5165;&#x53E3;&#x8BBE;&#x7F6E;&#x4E3A; __alltraps</span>
        <span class="token namespace">stvec<span class="token punctuation">::</span></span><span class="token function">write</span><span class="token punctuation">(</span>__alltraps <span class="token keyword">as</span> <span class="token keyword">usize</span><span class="token punctuation">,</span> <span class="token namespace">stvec<span class="token punctuation">::</span></span><span class="token class-name">TrapMode</span><span class="token punctuation">::</span><span class="token class-name">Direct</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token macro property">println!</span><span class="token punctuation">(</span><span class="token string">&quot;++++ setup interrupt! ++++&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x5220;&#x9664;&#x539F;&#x6765;&#x7684; trap_handler &#xFF0C;&#x6539;&#x6210; rust_trap</span>
<span class="token comment">// &#x4EE5; &amp;mut TrapFrame &#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#xFF0C;&#x56E0;&#x6B64;&#x53EF;&#x4EE5;&#x77E5;&#x9053;&#x4E2D;&#x65AD;&#x76F8;&#x5173;&#x4FE1;&#x606F;</span>
<span class="token comment">// &#x5728;&#x8FD9;&#x91CC;&#x8FDB;&#x884C;&#x4E2D;&#x65AD;&#x5206;&#x53D1;&#x53CA;&#x5904;&#x7406;</span>
<span class="token attribute attr-name">#[no_mangle]</span>
<span class="token keyword">pub</span> <span class="token keyword">fn</span> <span class="token function-definition function">rust_trap</span><span class="token punctuation">(</span>tf<span class="token punctuation">:</span> <span class="token operator">&amp;</span><span class="token keyword">mut</span> <span class="token class-name">TrapFrame</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token macro property">println!</span><span class="token punctuation">(</span><span class="token string">&quot;rust_trap!&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">// &#x89E6;&#x53D1;&#x4E2D;&#x65AD;&#x65F6;&#xFF0C;&#x786C;&#x4EF6;&#x4F1A;&#x5C06; sepc &#x8BBE;&#x7F6E;&#x4E3A;&#x89E6;&#x53D1;&#x4E2D;&#x65AD;&#x6307;&#x4EE4;&#x7684;&#x5730;&#x5740;</span>
    <span class="token comment">// &#x800C;&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x7ED3;&#x675F;&#xFF0C;&#x4F7F;&#x7528; sret &#x8FD4;&#x56DE;&#x65F6;&#x4E5F;&#x4F1A;&#x8DF3;&#x8F6C;&#x5230; sepc &#x5904;</span>
    <span class="token comment">// &#x4E8E;&#x662F;&#x6211;&#x4EEC;&#x53C8;&#x8981;&#x6267;&#x884C;&#x4E00;&#x6B21;&#x90A3;&#x6761;&#x6307;&#x4EE4;&#xFF0C;&#x89E6;&#x53D1;&#x4E2D;&#x65AD;&#xFF0C;&#x65E0;&#x9650;&#x5FAA;&#x73AF;&#x4E0B;&#x53BB;</span>
    <span class="token comment">// &#x800C;&#x6211;&#x4EEC;&#x8FD9;&#x91CC;&#x662F;&#x65AD;&#x70B9;&#x4E2D;&#x65AD;&#xFF0C;&#x53EA;&#x60F3;&#x8FD9;&#x4E2A;&#x4E2D;&#x65AD;&#x89E6;&#x53D1;&#x4E00;&#x6B21;</span>
    <span class="token comment">// &#x56E0;&#x6B64;&#x6211;&#x4EEC;&#x5C06;&#x4E2D;&#x65AD;&#x5E27;&#x5185;&#x7684; sepc &#x5B57;&#x6BB5;&#x8BBE;&#x7F6E;&#x4E3A;&#x89E6;&#x53D1;&#x4E2D;&#x65AD;&#x6307;&#x4EE4;&#x4E0B;&#x4E00;&#x6761;&#x6307;&#x4EE4;&#x7684;&#x5730;&#x5740;&#xFF0C;&#x5373;&#x4E2D;&#x65AD;&#x7ED3;&#x675F;&#x540E;&#x8DF3;&#x8FC7;&#x8FD9;&#x6761;&#x8BED;&#x53E5;</span>
    <span class="token comment">// &#x7531;&#x4E8E; riscv64 &#x7684;&#x6BCF;&#x6761;&#x6307;&#x4EE4;&#x90FD;&#x662F; 32 &#x4F4D;&#xFF0C;4 &#x5B57;&#x8282;&#xFF0C;&#x56E0;&#x6B64;&#x5C06;&#x5730;&#x5740;+ 4 &#x5373;&#x53EF;</span>
    <span class="token comment">// &#x8FD9;&#x6837;&#x5728; RESTORE_ALL &#x65F6;&#xFF0C;&#x8FD9;&#x4E2A;&#x4FEE;&#x6539;&#x540E;&#x7684; sepc &#x5B57;&#x6BB5;&#x5C31;&#x4F1A;&#x88AB; load &#x5230; sepc &#x5BC4;&#x5B58;&#x5668;&#x4E2D;</span>
    <span class="token comment">// &#x4F7F;&#x7528; sret &#x8FD4;&#x56DE;&#x65F6;&#x5C31;&#x4F1A;&#x8DF3;&#x8F6C;&#x5230; ebreak &#x7684;&#x4E0B;&#x4E00;&#x6761;&#x6307;&#x4EE4;&#x4E86;</span>
    tf<span class="token punctuation">.</span>sepc <span class="token operator">+=</span> <span class="token number">4</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x770B;&#x8D77;&#x6765;&#x5F88;&#x5BF9;&#xFF0C;&#x90A3;&#x6211;&#x4EEC; <code>make run</code> &#x8FD0;&#x884C;&#x4E00;&#x4E0B;&#x5427;&#xFF01;</p>
<blockquote>
<p><strong>[danger] infinite rust_trap</strong></p>
<p>&#x7ED3;&#x679C;&#x5374;&#x4E0D;&#x5C3D;&#x5982;&#x4EBA;&#x610F;&#xFF0C;&#x8F93;&#x51FA;&#x4E86;&#x4E00;&#x5927;&#x5806;&#x4E71;&#x7801;&#xFF01;</p>
</blockquote>
<p>&#x6211;&#x4EEC;&#x4F7F;&#x7528; <code>make asm</code> &#x68C0;&#x67E5;&#x4E00;&#x4E0B;&#x751F;&#x6210;&#x7684;&#x6C47;&#x7F16;&#x4EE3;&#x7801;&#xFF0C;&#x770B;&#x770B;&#x662F;&#x4E0D;&#x662F;&#x54EA;&#x91CC;&#x51FA;&#x4E86;&#x95EE;&#x9898;&#x3002;&#x627E;&#x5230;&#x6211;&#x4EEC;&#x624B;&#x52A8;&#x89E6;&#x53D1;&#x4E2D;&#x65AD;&#x7684; <code>ebreak</code> &#x6307;&#x4EE4;&#xFF1A;</p>
<pre class="language-"><code class="lang-riscv">...
<span class="token number">0000000080200010</span> <span class="token labels operator">rust_main:</span>
<span class="token labels operator">80200010:</span> <span class="token number">01</span> <span class="token number">11</span>                         <span class="token rv32/64i-instructions keyword">addi</span>    <span class="token general-registers class-name">sp</span>, <span class="token general-registers class-name">sp</span>, -<span class="token number">32</span>
<span class="token labels operator">80200012:</span> <span class="token number">06</span> <span class="token number">ec</span>                         <span class="token rv32/64i-instructions keyword">sd</span>      <span class="token general-registers class-name">ra</span>, <span class="token number">24</span>(<span class="token general-registers class-name">sp</span>)
<span class="token labels operator">80200014:</span> <span class="token number">22</span> <span class="token number">e8</span>                         <span class="token rv32/64i-instructions keyword">sd</span>      <span class="token general-registers class-name">s0</span>, <span class="token number">16</span>(<span class="token general-registers class-name">sp</span>)
<span class="token labels operator">80200016:</span> <span class="token number">00</span> <span class="token number">10</span>                         <span class="token rv32/64i-instructions keyword">addi</span>    <span class="token general-registers class-name">s0</span>, <span class="token general-registers class-name">sp</span>, <span class="token number">32</span>
<span class="token labels operator">80200018:</span> <span class="token number">97</span> <span class="token number">00</span> <span class="token number">00</span> <span class="token number">00</span>                   <span class="token rv32/64i-instructions keyword">auipc</span>   <span class="token general-registers class-name">ra</span>, <span class="token number">0</span>
<span class="token labels operator">8020001c:</span> <span class="token number">e7</span> <span class="token number">80</span> <span class="token number">40</span> <span class="token number">10</span>                   <span class="token rv32/64i-instructions keyword">jalr</span>    <span class="token number">260</span>(<span class="token general-registers class-name">ra</span>)
<span class="token labels operator">80200020:</span> <span class="token number">09</span> <span class="token general-registers class-name">a0</span>                         <span class="token pseudo-instructions important">j</span>       <span class="token number">2</span>
<span class="token labels operator">80200022:</span> <span class="token number">02</span> <span class="token number">90</span>                         <span class="token privilege-instructions keyword">ebreak</span>

<span class="token number">0000000080200024</span> <span class="token labels operator">.LBB0_3:</span>
<span class="token labels operator">80200024:</span> <span class="token number">17</span> <span class="token number">35</span> <span class="token number">00</span> <span class="token number">00</span>                   <span class="token rv32/64i-instructions keyword">auipc</span>   <span class="token general-registers class-name">a0</span>, <span class="token number">3</span>
...
</code></pre>
<p>&#x4E0D;&#x662F;&#x8BF4; riscv64 &#x91CC;&#x9762;&#x6BCF;&#x6761;&#x6307;&#x4EE4;&#x957F;&#x5EA6;&#x4E3A; 4 &#x5B57;&#x8282;&#x5417;&#xFF1F;&#x6211;&#x4EEC;&#x53D1;&#x73B0; <code>ebreak</code> &#x8FD9;&#x6761;&#x6307;&#x4EE4;&#x4EC5;&#x957F;&#x4E3A; 2 &#x5B57;&#x8282;&#x3002;&#x6211;&#x4EEC;&#x5C06; <code>ebreak</code> &#x6240;&#x5728;&#x7684;&#x5730;&#x5740; +4 &#xFF0C;&#x5F97;&#x5230;&#x7684;&#x751A;&#x81F3;&#x4E0D;&#x662F;&#x4E00;&#x6761;&#x5408;&#x6CD5;&#x6307;&#x4EE4;&#x7684;&#x5F00;&#x5934;&#xFF0C;&#x800C;&#x662F;&#x4E0B;&#x4E00;&#x6761;&#x6307;&#x4EE4;&#x6B63;&#x4E2D;&#x95F4;&#x7684;&#x5730;&#x5740;&#xFF01;&#x8FD9;&#x6837;&#x5F53;&#x7136;&#x6709;&#x95EE;&#x9898;&#x4E86;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x56DE;&#x5934;&#x6765;&#x770B; riscv64 &#x76EE;&#x6807;&#x4E09;&#x5143;&#x7EC4;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x8BBE;&#x7F6E;&#xFF1A;</p>
<pre class="language-"><code class="lang-json"><span class="token property">&quot;features&quot;</span><span class="token operator">:</span> <span class="token string">&quot;+m,+a,+c&quot;</span><span class="token punctuation">,</span>
</code></pre>
<p>&#x5B9E;&#x9645;&#x4E0A;&#xFF0C;&#x8FD9;&#x8868;&#x793A;&#x6307;&#x4EE4;&#x96C6;&#x7684;&#x62D3;&#x5C55;&#x3002;<code>+m</code> &#x8868;&#x793A;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x6574;&#x6570;&#x4E58;&#x9664;&#x6CD5;&#x6307;&#x4EE4;&#xFF1B; <code>+a</code> &#x8868;&#x793A;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x539F;&#x5B50;&#x64CD;&#x4F5C;&#x6307;&#x4EE4;&#xFF1B; <code>+c</code> &#x8868;&#x793A;&#x5F00;&#x542F;&#x538B;&#x7F29;&#x6307;&#x4EE4;&#x96C6;&#xFF0C;&#x5373;&#x5BF9;&#x4E8E;&#x4E00;&#x4E9B;&#x5E38;&#x89C1;&#x6307;&#x4EE4;&#xFF0C;&#x7F16;&#x8BD1;&#x5668;&#x4F1A;&#x5C06;&#x5176;&#x538B;&#x7F29;&#x5230; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>1</mn><mn>6</mn></mrow><annotation encoding="application/x-tex">16</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">1</span><span class="mord mathrm">6</span></span></span></span> &#x4F4D;&#x5373; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>2</mn></mrow><annotation encoding="application/x-tex">2</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">2</span></span></span></span> &#x5B57;&#x8282;&#xFF0C;&#x6765;&#x964D;&#x4F4E;&#x53EF;&#x6267;&#x884C;&#x6587;&#x4EF6;&#x7684;&#x5927;&#x5C0F;&#xFF01;&#x8FD9;&#x5C31;&#x51FA;&#x73B0;&#x4E86;&#x4E0A;&#x9762;&#x90A3;&#x79CD;&#x8BE1;&#x5F02;&#x7684;&#x60C5;&#x51B5;&#x3002;</p>
<p>&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x53EA;&#x9700;&#x5C06; sepc &#x4FEE;&#x6B63;&#x4E3A; +2&#xFF1A;</p>
<pre class="language-"><code class="lang-diff"><span class="token deleted-sign deleted"><span class="token prefix deleted">-</span><span class="token line">    tf.sepc += 4;
</span></span><span class="token inserted-sign inserted"><span class="token prefix inserted">+</span><span class="token line">    tf.sepc += 2;
</span></span></code></pre>
<p>&#x518D; <code>make run</code> &#x5C1D;&#x8BD5;&#x4E00;&#x4E0B;&#xFF1A;</p>
<blockquote>
<p><strong>[success] back from trap </strong></p>
<pre class="language-"><code>++++ setup interrupt! ++++
rust_trap!
panicked at &apos;end of rust_main&apos;, src/init.rs:9:5
</code></pre></blockquote>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x6211;&#x4EEC;&#x786E;&#x5B9E;&#x624B;&#x52A8;&#x89E6;&#x53D1;&#x4E2D;&#x65AD;&#xFF0C;&#x8C03;&#x7528;&#x4E86;&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x51FD;&#x6570;&#xFF0C;&#x5E76;&#x901A;&#x8FC7;&#x4E0A;&#x4E0B;&#x6587;&#x4FDD;&#x5B58;&#x4E0E;&#x6062;&#x590D;&#x673A;&#x5236;&#x4FDD;&#x62A4;&#x4E86;&#x4E0A;&#x4E0B;&#x6587;&#x73AF;&#x5883;&#x4E0D;&#x53D7;&#x5230;&#x7834;&#x574F;&#xFF0C;&#x6B63;&#x786E;&#x5728; <code>ebreak</code> &#x4E2D;&#x65AD;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x8FD4;&#x56DE;&#x4E4B;&#x540E; <code>panic</code>&#x3002;</p>
<p>&#x8FC4;&#x4ECA;&#x4E3A;&#x6B62;&#x7684;&#x4EE3;&#x7801;&#x53EF;&#x4EE5;&#x5728;<a href="https://github.com/rcore-os/rCore_tutorial/tree/ch3-pa4" target="_blank">&#x8FD9;&#x91CC;</a>&#x627E;&#x5230;&#x3002;&#x5982;&#x679C;&#x51FA;&#x73B0;&#x4E86;&#x95EE;&#x9898;&#x7684;&#x8BDD;&#x5C31;&#x6765;&#x68C0;&#x67E5;&#x4E00;&#x4E0B;&#x5427;&#x3002;</p>
<p><div id="page-footer" class="localized-footer"><hr><p><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css"></p>
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<div id="gitalk-container"></div>
<script>
  var gitalk = new Gitalk({
    clientID: "ab871063a9fa7f1da571",
    clientSecret: "4760b384e3e452d2241d859cfa6a7da21a8729ec",
    repo: "rCore_tutorial_doc",
    owner: "rcore-os",
    admin: [
      "chyyuu",
      "xyongcn",
      "wangrunji0408",
      "xy-plus",
      "PanQL",
      "wyfcyx",
      "equation314"
    ],
    id: location.pathname,
    distractionFreeMode: false
  });
  gitalk.render("gitalk-container");
</script>
</div></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="part3.html" class="navigation navigation-prev " aria-label="Previous page: 程序运行上下文环境">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="part5.html" class="navigation navigation-next " aria-label="Next page: [时钟中断]">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"[实现上下文环境保存与恢复]","level":"1.5.4","depth":2,"next":{"title":"[时钟中断]","level":"1.5.5","depth":2,"path":"chapter3/part5.md","ref":"chapter3/part5.md","articles":[]},"previous":{"title":"程序运行上下文环境","level":"1.5.3","depth":2,"path":"chapter3/part3.md","ref":"chapter3/part3.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["hide-element","chapter-fold","katex","alerts","emphasize","-highlight","prism","localized-footer","mermaid-gb3"],"pluginsConfig":{"chapter-fold":{},"prism":{"css":["prismjs/themes/prism-tomorrow.css"]},"emphasize":{},"search":{},"localized-footer":{"filename":"extensions/comment/gitalk.html","hline":"true"},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"hide-element":{"elements":[".gitbook-link"]},"katex":{},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"alerts":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"chapter3/part4.md","mtime":"2020-09-09T11:31:56.895Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-09-10T06:57:01.716Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-hide-element/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-alerts/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    <script src="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>

    </body>
</html>

